package com.lijian.reptile.utils;

import java.io.FileWriter;

/**
 * ClassName: WriteData
 * Description:  读写工具，将数据写入文件
 * date: 2021/11/25 0025 下午 3:32
 *
 * @author LiJian
 * @since JDK 1.8
 */
public abstract class WriteData {
    public static synchronized void writeData(String str){
        //以句号作为拆分
        String[] rex = str.split(" ");
        StringBuilder stringBuilder = new StringBuilder();
        String fileName = String.valueOf(System.currentTimeMillis());
        String path = "C:\\"+fileName+".txt";
       //每5句作为一段输出
        for (int i = 0; i <rex.length; i++) {
            stringBuilder.append(rex[i]);
            if (i % 5 == 0){
                stringBuilder.append("\r\n");

                try (FileWriter out = new FileWriter(path,true)) {
                    out.write(String.valueOf(stringBuilder));
                } catch (Exception e) {
                }

            }
        }

    }
}
